package servlet;

import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.servlet.ServletException;

import bean.PizzaBean;

import toolkit.Debug;

public class OrderServlet extends AbstractStepServlet
{
	private static final long serialVersionUID = 1L;
	
	public OrderServlet()
	{
		Debug.log("(" + id + ") OrderServlet()");
	}
	
	@Override
	public void dispatchGet()
			throws ServletException, IOException
	{
		Debug.log("(" + id + ") PizzaServlet.dispatchGet()");

		try
		{
			PizzaBean pizza = (PizzaBean) session.getAttribute("pizza");
			
			GregorianCalendar calendar = new GregorianCalendar();
			calendar.add(Calendar.MINUTE, 15);
			
			String delivery = "" + calendar.get(Calendar.HOUR)
				+ ":" + calendar.get(Calendar.MINUTE)
				+ " " + calendar.get(Calendar.DAY_OF_MONTH)
				+ "/" + calendar.get(Calendar.MONTH)
				+ "/" + calendar.get(Calendar.YEAR);
			
			System.out.println("------------------");
			System.out.println(pizza);
			
			request.setAttribute("deliveryTime", delivery);
			request.setAttribute("pizza", pizza);
		}
		catch (ClassCastException e)
		{
			e.printStackTrace();
		}
		
		display();
		
		nextStep();
	}
	
	@Override
	public void dispatchPost()
			throws ServletException, IOException
	{
		Debug.log("(" + id + ") PizzaServlet.dispatchPost()");
		
		dispatchGet();
	}
}
